package com.huibei.wateradmin.authority.message;


import com.huibei.wateradmin.authority.domain.Menu;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by wanglinlin on 2016/7/20.
 */
public class ClientMenuInfo {
    Long menuId;
    String name;
    String icon;
    String url;
    String parentMenuName;
    Long parentMenuId;
    List<ClientMenuInfo> menuInfos = new ArrayList<>();

    public ClientMenuInfo() {
    }

    public ClientMenuInfo(Menu menu) {
        this.menuId = menu.getId();
        this.name = menu.getName();
        this.icon = menu.getIcon();
        this.url = menu.getUrl();
        this.parentMenuId = menu.getParentMenu()!=null?menu.getParentMenu().getId():null;
        this.parentMenuName =menu.getParentMenu()!=null? menu.getParentMenu().getName():null;

    }

    public ClientMenuInfo(Menu menu ,List<ClientMenuInfo> menus) {
        this.menuId = menu.getId();
        this.name = menu.getName();
        this.icon = menu.getIcon();
        this.url = menu.getUrl();
        this.parentMenuId = menu.getParentMenu()!=null?menu.getParentMenu().getId():null;
        this.parentMenuName =menu.getParentMenu()!=null? menu.getParentMenu().getName():null;
        this.menuInfos = menus;
    }

    public static ClientMenuInfo convertToClientMenu(Menu menu, List<Menu> userMenuList) {

        List<ClientMenuInfo> menus = menu.getMenus().stream().filter(menu1 -> userMenuList.contains(menu1)).map((menu1) -> convertToClientMenu(menu1, userMenuList)).collect(Collectors.toList());
        return new ClientMenuInfo(menu, menus);
    }

    public Long getMenuId() {
        return menuId;
    }

    public void setMenuId(Long menuId) {
        this.menuId = menuId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getParentMenuName() {
        return parentMenuName;
    }

    public void setParentMenuName(String parentMenuName) {
        this.parentMenuName = parentMenuName;
    }

    public Long getParentMenuId() {
        return parentMenuId;
    }

    public void setParentMenuId(Long parentMenuId) {
        this.parentMenuId = parentMenuId;
    }

    public List<ClientMenuInfo> getMenuInfos() {
        return menuInfos;
    }

    public void setMenuInfos(List<ClientMenuInfo> menuInfos) {
        this.menuInfos = menuInfos;
    }
}
